﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using vHCS.HR.Entities;
using vHCS.HR.Business;
using Core.Controls.Message;
using System.Data;
using Telerik.Web.UI;
using Core.Message.Entities;
using Core.ExceptionHandling;
using vHCS.LS.Business;
using Core.Common.Session;
using Aspose.Cells;
using System.Collections;
using System.IO;
using System.Configuration;
using vHCS.SYS.Entities;

namespace vHCS.K2App.MdlK2.ExitCheckList.Ver1
{
    public partial class Ter_ExitFormApprove : Core.NTier.UserInterface.BaseFormNotPer
    {
        #region CONST

        protected const long _Deparment_Manager_ = 1;
        protected const long _FA_Deparment_ = 4;
        protected const long _FA_Other_ = 13;
        protected const long _HR_Other_Deparment_ = 8;
        protected const long _AF_Deparment_ = 2;
        protected const long _AF_Other_ = 11;
        protected const long _HR_Deparment_ = 3;
        protected const long _HR_Training_ = 10;
        protected const long _IT_Deparment_ = 1;
        protected const long _IT_Other_ = 12;
        protected const string _DeptHead_Role_ = "DeptHead";
        protected const string _FA_Role_ = "Accounting";
        protected const string _FAOther_Role_ = "AccOther";
        protected const string _HROther_Role_ = "HROther";
        protected const string _AF_Role_ = "AF";
        protected const string _AFOther_Role_ = "AFOther";
        protected const string _HR_Role_ = "HR";
        protected const string _HRTraining_Role_ = "HRTraining";
        protected const string _IT_Role_ = "IT";
        protected const string _ITOther_Role_ = "ITOther";
        protected const string _HRBP_ = "HRBP";
        protected const string _HRExcutor_ = "HRExcutor";
        protected const string _EmpID = "EmpID";
        private const string _FileName = "ExitForm-Export.xls";
        protected const string _TicketName__ = "Exit Checklist";
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    hdfsn.Value = Request.QueryString["SN"] == null ? "" : Request.QueryString["SN"].ToString();
                    string hrp = "";
                    string hr_excutor = "";
                    string IsReturn = "";
                    try
                    {
                        K2Collection colK2 = new K2Collection();
                        string sharedUser = Request.QueryString["SharedUser"] != null ? Request.QueryString["SharedUser"].ToString() : string.Empty;
                        hdfEmpID.Value = K2CoreLib.K2Utils.GetDataField(hdfsn.Value.Trim(), "EmpID", sharedUser);
                        txtEmpID.Text = hdfEmpID.Value;
                        hrp = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "HRBP", sharedUser);
                        hr_excutor = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "HRExcutor", sharedUser);
                        IsReturn = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "IsReturn", sharedUser);
                    }
                    catch (Exception ex)
                    {
                        btnBottomSave.Enabled = false;
                        btnTopSave.Enabled = false;
                        //BusinessLogicCustomException ex = new BusinessLogicCustomException("12634");
                        throw ex;
                    }

                    this.EmpHeader.LoadEmpInfoByEmpId(Convert.ToInt64(hdfEmpID.Value));
                    LoadContainExit();
                    LoadInfor();

                    //Lấy thông tin chỗ ngồi của nhân viên
                    HR_WorkingRecordBL bl = new HR_WorkingRecordBL();
                    HR_WorkingRecordCollection cl = new HR_WorkingRecordCollection();
                    bl = cl.SelectLastWRByEmpID(EmpHeader.EmployeeId);
                    if (bl.DTO != null)
                        lblITOther.Text = lblITOther.Text.Replace("$Seat$", string.IsNullOrEmpty(bl.Seat)?"":bl.Seat);

                    //Hiển thị thông tin excutor nếu là HRBP duyệt
                    if (!string.IsNullOrEmpty(hrp) && string.IsNullOrEmpty(hr_excutor) && (IsReturn=="0" || string.IsNullOrEmpty(IsReturn)))
                    {
                        pnlHRBP.Visible = true;
                        //pnlXacnhan.Visible = true;
                    }
                    //Hiển thị thông tin approve/return nếu là C&B phê duyệt
                    if (!string.IsNullOrEmpty(hr_excutor) && (IsReturn == "0" || string.IsNullOrEmpty(IsReturn)))
                    {
                        PnlCB.Visible = true;
                    }

                    TER_ExitFormCollection cl_exit = new TER_ExitFormCollection();
                    dtsHistoryApprove.SelectParameters["ID"].DefaultValue =cl_exit.GetProcessid(EmpHeader.EmployeeId);
                    dtgHistoryApprove.DataSourceID = dtsHistoryApprove.ID;
                    dtsHistoryApprove.DataBind();

                    #region Lấy thông tin HRBP
                    K2Collection col_k2 = new K2Collection();
                    HR_EmpCVCollection cl_empcv = new HR_EmpCVCollection();
                    string HRBP = col_k2.GetUserOfHRP_Province(EmpHeader.EmployeeId);
                    string NameHRBP = cl_empcv.GetDisplayNameByUser(HRBP);
                    long EmpID_HRBP = cl_empcv.GetEmpIdByUsername(HRBP);
                    string ext = "";
                    if (EmpID_HRBP > 0)
                    {
                        bl = cl.SelectLastWRByEmpID_ForFormWR1(EmpID_HRBP);
                        if (bl.DTO != null)
                        {
                            ext = bl.ExtNo;
                        }
                    }

                    lblConsult.Text = lblConsult.Text.Replace("$HRBP$", NameHRBP);
                    lblConsult.Text = lblConsult.Text.Replace("$ext$",string.IsNullOrEmpty(ext)?"":ext.Trim());
                    #endregion

                    #region Lấy thông tin người request có quan tâm đến thông tin trợ cấp thất nghiệp hay không
                    TER_ExitFormCollection cl_exitform = new TER_ExitFormCollection();
                    if (cl_exitform.ReturnAllowanceInf(Convert.ToInt64(string.IsNullOrEmpty(hdfEmpID.Value) ? "0" : hdfEmpID.Value)))
                    {
                        radBenifit_Y.Checked = true;
                        radBenifit_N.Checked = false;
                    }
                    else
                    {
                        radBenifit_Y.Checked = false;
                        radBenifit_N.Checked = true;
                    }

                    if (cl_exitform.ReturnConsultInf(Convert.ToInt64(string.IsNullOrEmpty(hdfEmpID.Value) ? "0" : hdfEmpID.Value)))
                    {
                        radConsult_Y.Checked = true;
                        radConsult_N.Checked = false;
                    }
                    else
                    {
                        radConsult_Y.Checked = false;
                        radConsult_N.Checked = true;
                    }

                    #endregion

                    ClientScript.RegisterStartupScript(Page.GetType(), "Consult", "CheckConsult();", true);

                    #region Ẩn các lưới không có dữ liệu
                    dtgHRTraining.DataBind();
                    if (dtgHRTraining.Items.Count <= 0)
                        pnlHRTraining.Visible = false;
                    if (dtgDMList.Items.Count <= 0)
                        pnlDMList.Visible = false;
                    if (dtgAFList.Items.Count <= 0)
                        pnlAFList.Visible = false;
                    if (dtgAFListOther.Items.Count <= 0)
                        pnlAFListOther.Visible = false;
                    if (dtgITList.Items.Count <= 0)
                        pnlITList.Visible = false;
                    if (dtgITOther.Items.Count <= 0)
                        pnlITOther.Visible = false;
                    if (dtgFAList.Items.Count <= 0)
                        pnlFAList.Visible = false;
                    if (dtgFAListOther.Items.Count <= 0)
                        pnlFAListOther.Visible = false;
                    if (dtgHRList.Items.Count <= 0)
                        pnlHRList.Visible = false;
                    if (dtgHROtherList.Items.Count <= 0)
                        pnlHROtherList.Visible = false;
                    #endregion

                    #region Gán role ID cho cấp hiện tại phê duyệt
                    hdfExitType.Value = Request.QueryString["ExitType"] == null ? "0" : Request.QueryString["ExitType"].ToString();
                    hdfProperty.Value = Request.QueryString["Property"] == null ? "0" : Request.QueryString["Property"].ToString();
                    long exittype = 0;
                    long property = 0;
                    long.TryParse(hdfExitType.Value, out exittype);
                    long.TryParse(hdfProperty.Value, out property);
                    if (property > 0)
                    {
                        switch (exittype)
                        {
                            case _IT_Deparment_:
                                hdfRoleID.Value = cl.GetK2RoleID(_IT_Role_).ToString();
                                break;
                            case _AF_Deparment_:
                                hdfRoleID.Value = cl.GetK2RoleID(_AF_Role_).ToString();
                                break;
                            case _HR_Deparment_:
                                hdfRoleID.Value = cl.GetK2RoleID(_HR_Role_).ToString();
                                break;
                        }
                    }
                    else
                    {
                        if (exittype > 0)
                        {
                            switch (exittype)
                            {
                                case _Deparment_Manager_:
                                    hdfRoleID.Value = cl.GetK2RoleID(_DeptHead_Role_).ToString();
                                    break;
                                case _AF_Other_:
                                    hdfRoleID.Value = cl.GetK2RoleID(_AFOther_Role_).ToString();
                                    break;
                                case _IT_Other_:
                                    hdfRoleID.Value = cl.GetK2RoleID(_ITOther_Role_).ToString();
                                    break;
                                case _FA_Deparment_:
                                    hdfRoleID.Value = cl.GetK2RoleID(_FA_Role_).ToString();
                                    break;
                                case _FA_Other_:
                                    hdfRoleID.Value = cl.GetK2RoleID(_FAOther_Role_).ToString();
                                    break;
                                case _HR_Other_Deparment_:
                                    hdfRoleID.Value = cl.GetK2RoleID(_HROther_Role_).ToString();
                                    break;
                                case _HR_Training_:
                                    hdfRoleID.Value = cl.GetK2RoleID(_HRTraining_Role_).ToString();
                                    break;
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(hrp) && string.IsNullOrEmpty(hr_excutor))
                            {
                                hdfRoleID.Value = cl.GetK2RoleID(_HRBP_).ToString();
                            }
                            else
                            {
                                hdfRoleID.Value = cl.GetK2RoleID(_HRExcutor_).ToString();
                            }
                        }
                    }

                    #endregion
                }
                
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }
        /// <summary>
        /// reset các control về rỗng
        /// </summary>
        protected void SetEmpty()
        {
            try
            {
                txtEndDate.Text = null;
                txtStartDate.Text = null;
                this.EmpHeader.LoadEmpInfoByEmpId(0);
                dtsDMList.SelectParameters["empId"].DefaultValue = null;
                dtsDMList.CacheClear();

                dtgDMList.Rebind();
                dtsHROtherList.SelectParameters["empId"].DefaultValue = null;
                dtsHROtherList.CacheClear();

                dtgHROtherList.Rebind();
                dtsFAList.SelectParameters["empId"].DefaultValue = null;
                dtsFAList.CacheClear();
                dtgFAList.Rebind();
                dtsAFList.CacheClear();
                dtgAFList.Rebind();
                dtsITList.CacheClear();
                dtgITList.Rebind();
                dtsHRList.CacheClear();
                dtgHRList.Rebind();

            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }
        /// <summary>
        /// Load thông tin biên bản bàn giao thôi việc
        /// </summary>
        protected void LoadContainExit()
        {
            try
            {
                LS_ExitFormCollection cl = new LS_ExitFormCollection();
                HR_WorkingRecordBL bl_wr = new HR_WorkingRecordBL();
                HR_WorkingRecordCollection cl_wr = new HR_WorkingRecordCollection();
                HIE_EmpInHierarchyCollection cl_emphie = new HIE_EmpInHierarchyCollection();
                HIE_HierarchyBL bl_hie = new HIE_HierarchyBL();
                HIE_HierarchyCollection cl_hie = new HIE_HierarchyCollection();
                K2Collection colK2 = new K2Collection();

                #region Lấy thông tin Dept Head có thuộc FA Other
                //Lấy thông tin WR hiện tại của nhân viên
                bl_wr = cl_wr.SelectLastWRByEmpID(EmpHeader.EmployeeId);

                long hierarchyid = 0;
                if (bl_wr.DTO != null)
                    hierarchyid = bl_wr.HierarchyId;

                //

                //Lấy thông tin Dept Head của nhân viên
                long DeptID = cl_emphie.SelectDeptHie(hierarchyid);

                bool CheckFAOther = colK2.CheckDeptFA(DeptID.ToString());
                hdfCheckFAOther.Value = CheckFAOther.ToString();
                //
                #endregion

                //load tài sản phòng AF cấp
                if (cl.LoadViewDMProperty(_AF_Deparment_, this.EmpHeader.EmployeeId,0,0) != null)
                {
                    lblAF.Visible = true;
                    this.dtgAFList.Visible = true;
                    dtsAFList.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                    dtsAFList.CacheClear();
                    dtgAFList.Rebind();
                }
                //load tài sản phòng IT cấp
                if (cl.LoadViewDMProperty(_IT_Deparment_, this.EmpHeader.EmployeeId,0,0) != null)
                {
                    lblIT.Visible = true;
                    this.dtgITList.Visible = true;
                    dtsITList.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                    dtsITList.CacheClear();
                    dtgITList.Rebind();
                }
                //load tài sản phòng HR cấp
                if (cl.LoadViewDMProperty(_HR_Deparment_, this.EmpHeader.EmployeeId, 0, 0) != null)
                {
                    lblHR.Visible = true;
                    this.dtgHRList.Visible = true;
                    dtsHRList.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                    dtsHRList.CacheClear();
                    dtgHRList.Rebind();
                }

                dtsDMList.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                dtgDMList.Rebind();

                dtsHROtherList.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                dtgHROtherList.Rebind();

                dtsFAList.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                dtgFAList.Rebind();

                dtsAFListOther.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                dtgAFListOther.Rebind();

                dtsITOther.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                dtgITOther.Rebind();

                if (CheckFAOther)
                {
                    dtsFAListOther.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                    dtgFAListOther.Rebind();
                }
                else
                {
                    pnlFAListOther.Visible = false;
                }

                dtsHRTraining.SelectParameters["empId"].DefaultValue = this.EmpHeader.EmployeeId.ToString();
                dtgHRTraining.Rebind();
            }
            catch (Exception ex)
            {
                AlertMessage mess = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(mess);
            }

        }
        /// <summary>
        /// lấy thông tin ngày bắt đầu làm việc và kết thúc của nhân viên
        /// </summary>
        protected void LoadInfor()
        {
            try
            {
                TER_ExitFormCollection cl = new TER_ExitFormCollection();
                DataTable dat = new DataTable();
                dat = cl.SelectByEmpId(this.EmpHeader.EmployeeId);
                if (dat.Rows.Count > 0)
                {
                    if (dat.Rows[0]["JoinDate"].ToString().Trim() != "")
                        this.txtStartDate.Text = DateTime.Parse(dat.Rows[0]["JoinDate"].ToString().Trim()).ToShortDateString();
                    if (dat.Rows[0]["LastWorkingDate"].ToString().Trim() != "")
                        this.txtEndDate.Text = DateTime.Parse(dat.Rows[0]["LastWorkingDate"].ToString().Trim()).ToShortDateString();
                    else this.txtEndDate.Text = null;
                }

            }
            catch (Exception ex)
            {
                AlertMessage mess = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(mess);
            }
        }
        /// <summary>
        /// Xử lý sự kiện khi nhấn nút lưu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnTopSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.EmpHeader.EmployeeId > 0)
                {

                    LS_ExitFormCollection clExit = new LS_ExitFormCollection();
                    long lngCheck = clExit.CheckApprove(EmpHeader.EmployeeId);
                    //0:exit đã được phê duyệt thì không được hiệu chỉnh
                    if (lngCheck == 0)
                    {
                        MessageBox.ShowByMessCode("12294");
                        return;
                    }
                    TER_ExitFormCollection clDate = new TER_ExitFormCollection();
                    DataTable dat = new DataTable();
                    dat = clDate.SelectByEmpId(this.EmpHeader.EmployeeId);
                    TER_ExitFormCollection cl = new TER_ExitFormCollection();
                    List<HR_PropertyDTO> lstProperty = new List<HR_PropertyDTO>();
                    List<TER_ExitFormDTO> lstExit = new List<TER_ExitFormDTO>();
                    //lấy thông tin ở mục nhân sự (khác)
                    int isCheck = 0;
                    foreach (GridDataItem dataItem in dtgHROtherList.Items)
                    {
                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentHROther")).Text;
                        dto.FromDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateHROther")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsOther")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = dataItem["Approver"].Text;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.FromDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.FromDate <= Convert.ToDateTime(txtStartDate.Text) || dto.FromDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.FromDate <= Convert.ToDateTime(txtStartDate.Text) || dto.FromDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    isCheck++;
                        //}
                        lstExit.Add(dto);

                    }

                    foreach (GridDataItem dataItem in dtgHRTraining.Items)
                    {
                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentHROther")).Text;
                        dto.FromDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateHROther")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsOther")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = dataItem["Approver"].Text;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.FromDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.FromDate <= Convert.ToDateTime(txtStartDate.Text) || dto.FromDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.FromDate <= Convert.ToDateTime(txtStartDate.Text) || dto.FromDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    isCheck++;
                        //}
                        lstExit.Add(dto);

                    }

                    //kiểm tra ngày bàn giao
                    //if (isCheck++ == 0 && dtgHROtherList.Items.Count > 0 && pnlHROtherList.Visible==true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    //Lấy thông tin ở mục phòng hành chánh
                    foreach (GridDataItem dataItem in dtgFAList.Items)
                    {

                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentFA")).Text;
                        dto.FromDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateFA")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsFA")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = dataItem["Approver"].Text;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.FromDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.FromDate <= Convert.ToDateTime(txtStartDate.Text) || dto.FromDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.FromDate <= Convert.ToDateTime(txtStartDate.Text) || dto.FromDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    isCheck++;
                        //}
                        lstExit.Add(dto);
                    }
                    //kiểm tra ngày bàn giao  
                    //if (isCheck++ == 0 && dtgFAList.Items.Count > 0 && pnlFAList.Visible==true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    //lấy thông tin ở mục thông tin phòng ban
                    foreach (GridDataItem dataItem in dtgDMList.Items)
                    {

                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentDM")).Text;
                        dto.FromDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateDM")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsDM")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = dataItem["Approver"].Text;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.FromDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.FromDate <= Convert.ToDateTime(txtStartDate.Text) || dto.FromDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.FromDate <= Convert.ToDateTime(txtStartDate.Text) || dto.FromDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    isCheck++;
                        //}
                        lstExit.Add(dto);
                    }
                    //if (isCheck++ == 0 && dtgDMList.Items.Count > 0 && pnlDMList.Visible==true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    cl.AddNewApprove(lstExit,chkXacnhan.Checked);

                    //lấy thông tin tài sản của phòng AF
                    foreach (GridDataItem dataItem in dtgAFList.Items)
                    {

                        HR_PropertyDTO dto = new HR_PropertyDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentAF")).Text;
                        dto.IssueDate = Convert.ToDateTime(dataItem["FromDate"].Text);
                        dto.RecoveryDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtRecoveryDateAF")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsAF")).Text;
                        dto.PropertyID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.RecoveryDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    if (dto.RecoveryDate < dto.IssueDate)
                        //    {
                        //        MessageBox.ShowByMessCode("12302");
                        //        return;
                        //    }
                        //    isCheck++;
                        //}

                        lstProperty.Add(dto);
                    }
                    //if (isCheck++ == 0 && dtgAFList.Items.Count > 0 && pnlAFList.Visible==true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    //lấy thông tin tài sản của phòng IT
                    foreach (GridDataItem dataItem in dtgITList.Items)
                    {

                        HR_PropertyDTO dto = new HR_PropertyDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentIT")).Text;
                        dto.IssueDate = Convert.ToDateTime(dataItem["FromDate"].Text);
                        dto.RecoveryDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtRecoveryDateIT")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsIT")).Text;
                        dto.PropertyID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.RecoveryDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    if (dto.RecoveryDate < dto.IssueDate)
                        //    {
                        //        MessageBox.ShowByMessCode("12302");
                        //        return;
                        //    }
                        //    isCheck++;
                        //}

                        lstProperty.Add(dto);
                    }
                    //if (isCheck++ == 0 && dtgITList.Items.Count > 0 && pnlITList.Visible==true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    //lấy thông tin tài sản của phòng HR
                    foreach (GridDataItem dataItem in dtgHRList.Items)
                    {

                        HR_PropertyDTO dto = new HR_PropertyDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentHR")).Text;
                        dto.IssueDate = Convert.ToDateTime(dataItem["FromDate"].Text);
                        dto.RecoveryDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtRecoveryDateHR")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsHR")).Text;
                        dto.PropertyID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.RecoveryDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    if (dto.RecoveryDate < dto.IssueDate)
                        //    {
                        //        MessageBox.ShowByMessCode("12302");
                        //        return;
                        //    }
                        //    isCheck++;
                        //}

                        lstProperty.Add(dto);
                    }
                    //if (isCheck++ == 0 && dtgHRList.Items.Count > 0 && pnlHRList.Visible==true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    cl.AddNewPropertyApprove(lstProperty);
                    MessageBox.ShowByMessCode("10055");
                }
                else
                {
                    MessageBox.ShowByMessCode("10095", MessageType.Error);
                }
            }
            catch (Exception ex)
            {
                AlertMessage mess = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(mess);
            }

        }
        /// <summary>
        /// xử lý sự kiện khi nhấn button xuất dl
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnBottomExport_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.EmpHeader.EmployeeId > 0)
                {
                    LS_ExitFormCollection cl = new LS_ExitFormCollection();
                    DataTable datManager = new DataTable();
                    DataTable datAF = new DataTable();
                    DataTable datIT = new DataTable();
                    DataTable datFA = new DataTable();
                    DataTable datHR = new DataTable();
                    DataTable datOther = new DataTable();
                    DataTable dtReplace = new DataTable();
                    datManager = cl.GetExitContain(1, this.EmpHeader.EmployeeId, 0, 0);

                    if ((cl.LoadViewExitForm(1, this.EmpHeader.EmployeeId).Rows.Count <= 0))
                    {
                        datManager = cl.LoadViewExitDefault(1, this.EmpHeader.EmployeeId);
                    }
                    else
                        datManager = cl.GetExitContain(1, this.EmpHeader.EmployeeId, 0, 0);

                    datAF = cl.LoadViewDMProperty(2, this.EmpHeader.EmployeeId, 0, 0);

                    datIT = cl.LoadViewDMProperty(1, this.EmpHeader.EmployeeId, 0, 0);
                    if ((cl.LoadViewExitForm(4, this.EmpHeader.EmployeeId).Rows.Count <= 0))
                    {
                        datFA = cl.LoadViewExitDefault(4, this.EmpHeader.EmployeeId);
                    }
                    else
                        datFA = cl.GetExitContain(4, this.EmpHeader.EmployeeId, 0, 0);

                    datHR = cl.LoadViewDMProperty(3, this.EmpHeader.EmployeeId, 0, 0);

                    if ((cl.LoadViewExitForm(8, this.EmpHeader.EmployeeId).Rows.Count <= 0))
                    {
                        datOther = cl.LoadViewExitDefault(8, this.EmpHeader.EmployeeId);
                    }
                    else
                        datOther = cl.GetExitContain(8, this.EmpHeader.EmployeeId, 0, 0);

                    dtReplace = cl.LoadEmpInfo(EmpHeader.EmployeeId);
                    //  dtReplace = cl.SelectToReplace(hdfDevelopedPlanID.Value);
                    string filePath = this.Server.MapPath(HR_ConfigManager.TemplateReportHR + _FileName);
                    ExportExcel(filePath, datManager, datAF, datIT, datFA, datHR, datOther, dtReplace);
                }
                else
                {
                    MessageBox.ShowByMessCode("10095", MessageType.Error);
                }
            }
            catch (Exception ex)
            {
                AlertMessage mess = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(mess);
            }
        }
        /// <summary>
        /// xứ lý sự kiện khi nhấn nút phê duyệt
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnTopApprove_Click(object sender, EventArgs e)
        {
            try
            {
                //DungN2 bỏ các ràng buộc ngày bàn giao.
                if (this.EmpHeader.EmployeeId > 0)
                {
                    //LS_ExitFormCollection clExit = new LS_ExitFormCollection();
                    //long lngCheck = clExit.CheckApprove(EmpHeader.EmployeeId);
                    ////0:exit đã được phê duyệt thì không được hiệu chỉnh
                    //if (lngCheck == 0)
                    //{
                    //    MessageBox.ShowByMessCode("12294");
                    //    return;
                    //}
                    TER_ExitFormCollection cl = new TER_ExitFormCollection();
                    List<HR_PropertyDTO> lstProperty = new List<HR_PropertyDTO>();
                    List<TER_ExitFormDTO> lstExit = new List<TER_ExitFormDTO>();
                    //lấy thông tin ở mục nhân sự (khác)
                    int isCheck = 0;
                    foreach (GridDataItem dataItem in dtgHROtherList.Items)
                    {

                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentHROther")).Text;
                        dto.ToDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateHROther")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsOther")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = SessionManager.UserDomain;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.ToDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            break;
                        //        }
                        //    }
                        //    else
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            break;
                        //        }

                        //    if (dto.ToDate <= Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateHROther")).MinDate))
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }

                        //}
                        lstExit.Add(dto);
                    }

                    //isCheck = 0;
                    foreach (GridDataItem dataItem in dtgHRTraining.Items)
                    {

                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentHROther")).Text;
                        dto.ToDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateHROther")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsOther")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = SessionManager.UserDomain;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.FromDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            break;
                        //        }
                        //    }
                        //    else
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            break;
                        //        }

                        //    if (dto.ToDate <= Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateHROther")).MinDate))
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }

                        //}
                        lstExit.Add(dto);
                    }

                    isCheck = 0;
                    //Lấy thông tin ở mục phòng hành chánh
                    foreach (GridDataItem dataItem in dtgFAList.Items)
                    {
                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentFA")).Text;
                        dto.ToDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateFA")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsFA")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = SessionManager.UserDomain;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.ToDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }

                        //    if (dto.ToDate <= Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateFA")).MinDate))
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }
                        //    isCheck++;
                        //}
                        lstExit.Add(dto);
                    }

                    isCheck = 0;
                    bool CheckFAOther = Convert.ToBoolean(hdfCheckFAOther.Value);
                    if (CheckFAOther)
                    {
                        //Lấy thông tin ở mục phòng hành chánh
                        foreach (GridDataItem dataItem in dtgFAListOther.Items)
                        {
                            TER_ExitFormDTO dto = new TER_ExitFormDTO();
                            dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentDM")).Text;
                            dto.ToDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateDM")).SelectedDate);
                            dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsDM")).Text;
                            dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                            dto.CreatedUser = SessionManager.UserDomain;
                            dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                            dto.EmpID = this.EmpHeader.EmployeeId;
                            //if (dto.ToDate.ToString() != "")
                            //{
                            //    if (this.txtEndDate.Text != "")
                            //    {
                            //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > Convert.ToDateTime(txtEndDate.Text))
                            //        {
                            //            MessageBox.ShowByMessCode("12297");
                            //            return;
                            //        }
                            //    }
                            //    else
                            //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > DateTime.Now)
                            //        {
                            //            MessageBox.ShowByMessCode("12297");
                            //            return;
                            //        }

                            //    if (dto.ToDate <= DateTime.MinValue)
                            //    {
                            //        MessageBox.ShowByMessCode("12296");
                            //        break;
                            //    }
                            //    isCheck++;
                            //}
                            lstExit.Add(dto);
                        }
                    }

                    isCheck = 0;
                    //Lấy thông tin ở mục phòng hành chánh
                    foreach (GridDataItem dataItem in dtgAFListOther.Items)
                    {
                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentDM")).Text;
                        dto.ToDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateDM")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsDM")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = SessionManager.UserDomain;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.ToDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }

                        //    if (dto.ToDate <= DateTime.MinValue)
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }
                        //    isCheck++;
                        //}
                        lstExit.Add(dto);
                    }

                    //isCheck = 0;
                    //Lấy thông tin ở mục phòng hành chánh
                    foreach (GridDataItem dataItem in dtgITOther.Items)
                    {
                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentDM")).Text;
                        dto.ToDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateDM")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsDM")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = SessionManager.UserDomain;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.ToDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }

                        //    if (dto.ToDate <= DateTime.MinValue)
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }
                        //    isCheck++;
                        //}
                        lstExit.Add(dto);
                    }

                    //kiểm tra ngày bàn giao  
                    //if (isCheck++ == 0 && dtgAFList.Items.Count > 0 && pnlAFList.Visible == true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    //lấy thông tin ở mục thông tin phòng ban
                    foreach (GridDataItem dataItem in dtgDMList.Items)
                    {

                        TER_ExitFormDTO dto = new TER_ExitFormDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentDM")).Text;
                        dto.ToDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtTranferDateDM")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsDM")).Text;
                        dto.LSExitFormID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.CreatedUser = SessionManager.UserDomain;
                        dto.CreatedDate = Convert.ToDateTime(dataItem["ApproveDate"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.ToDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.ToDate <= Convert.ToDateTime(txtStartDate.Text) || dto.ToDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12297");
                        //            return;
                        //        }

                        //    if (dto.ToDate <= DateTime.MinValue)
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }
                        //    isCheck++;
                        //}
                        lstExit.Add(dto);
                    }
                    //kiểm tra ngày bàn giao  
                    //if (isCheck++ == 0 && dtgDMList.Items.Count > 0 && pnlDMList.Visible == true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    isCheck = 0;
                    cl.AddNewApprove(lstExit, chkXacnhan.Checked);
                    //lấy thông tin tài sản của phòng AF
                    foreach (GridDataItem dataItem in dtgAFList.Items)
                    {

                        HR_PropertyDTO dto = new HR_PropertyDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentAF")).Text;
                        dto.IssueDate = Convert.ToDateTime(dataItem["FromDate"].Text);
                        dto.RecoveryDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtRecoveryDateAF")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsAF")).Text;
                        dto.PropertyID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.RecoveryDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    if (dto.RecoveryDate < dto.IssueDate)
                        //    {
                        //        MessageBox.ShowByMessCode("12302");
                        //        return;
                        //    }

                        //    if (dto.RecoveryDate <= DateTime.MinValue)
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }
                        //    isCheck++;
                        //}
                        lstProperty.Add(dto);
                    }
                    //if (isCheck++ == 0 && dtgAFList.Items.Count > 0 && pnlAFList.Visible == true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    //lấy thông tin tài sản của phòng IT
                    foreach (GridDataItem dataItem in dtgITList.Items)
                    {

                        HR_PropertyDTO dto = new HR_PropertyDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentIT")).Text;
                        dto.IssueDate = Convert.ToDateTime(dataItem["FromDate"].Text);
                        dto.RecoveryDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtRecoveryDateIT")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsIT")).Text;
                        dto.PropertyID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.RecoveryDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    if (dto.RecoveryDate < dto.IssueDate)
                        //    {
                        //        MessageBox.ShowByMessCode("12302");
                        //        return;
                        //    }

                        //    if (dto.RecoveryDate <= DateTime.MinValue)
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }
                        //    isCheck++;
                        //}
                        lstProperty.Add(dto);
                    }
                    //if (isCheck++ == 0 && dtgITList.Items.Count > 0 && pnlITList.Visible == true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    //lấy thông tin tài sản của phòng HR
                    foreach (GridDataItem dataItem in dtgHRList.Items)
                    {

                        HR_PropertyDTO dto = new HR_PropertyDTO();
                        dto.Account = ((RadNumericTextBox)dataItem["ExitID"].FindControl("txtFinalPaymentHR")).Text;
                        dto.IssueDate = Convert.ToDateTime(dataItem["FromDate"].Text);
                        dto.RecoveryDate = Convert.ToDateTime(((RadDatePicker)dataItem["ExitID"].FindControl("txtRecoveryDateHR")).SelectedDate);
                        dto.Comment = ((RadTextBox)dataItem["ExitID"].FindControl("txtCommentsHR")).Text;
                        dto.PropertyID = Convert.ToInt64(dataItem["ExitID"].Text);
                        dto.EmpID = this.EmpHeader.EmployeeId;
                        //if (dto.RecoveryDate.ToString() != "")
                        //{
                        //    if (this.txtEndDate.Text != "")
                        //    {
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > Convert.ToDateTime(txtEndDate.Text))
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    }
                        //    else
                        //        if (dto.RecoveryDate <= Convert.ToDateTime(txtStartDate.Text) || dto.RecoveryDate > DateTime.Now)
                        //        {
                        //            MessageBox.ShowByMessCode("12302");
                        //            return;
                        //        }
                        //    if (dto.RecoveryDate < dto.IssueDate)
                        //    {
                        //        MessageBox.ShowByMessCode("12302");
                        //        return;
                        //    }

                        //    if (dto.RecoveryDate <= DateTime.MinValue)
                        //    {
                        //        MessageBox.ShowByMessCode("12296");
                        //        break;
                        //    }
                        //    isCheck++;
                        //}
                        lstProperty.Add(dto);
                    }
                    //if (isCheck++ == 0 && dtgHRList.Items.Count > 0 && pnlHRList.Visible == true)
                    //{
                    //    MessageBox.ShowByMessCode("12296");
                    //    return;
                    //}
                    //isCheck = 0;
                    cl.AddNewPropertyApprove(lstProperty);
                    Submit_K2();
                    MessageBox.ShowByMessCode("10055");
                    // Close page when submit 
                    ClientScript.RegisterStartupScript(Page.GetType(), "ClosePage", "ClosePage();", true);
                }
                else
                {
                    MessageBox.ShowByMessCode("10095", MessageType.Error);
                }
            }
            catch (Exception ex)
            {
                AlertMessage mess = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(mess);
            }
        }

        #region Export data follow template
        public string ExportExcel(string sPathFile, DataTable dtData, DataTable dtData_AF, DataTable dtData_IT, DataTable dtData_FA, DataTable dtData_HR, DataTable dtData_Other, DataTable dtReplace)
        {
            try
            {
                Workbook wb = new Workbook();
                wb.Open(sPathFile);

                #region Cau hinh tren worksheet2
                Worksheet ws_config = wb.Worksheets[1];
                //--Khai bao tham so cau hinh
                int iMax_Colum = Convert.ToInt16(ws_config.Cells["H4"].Value);
                int iRow_Group1 = Convert.ToInt16(ws_config.Cells["B4"].Value) - 1;
                int iRow_Group2 = Convert.ToInt16(ws_config.Cells["B5"].Value) - 1;
                int iRow_Detail = Convert.ToInt16(ws_config.Cells["B6"].Value) - 1;
                //begin
                int iRow_Detail_AF = Convert.ToInt16(ws_config.Cells["B9"].Value) - 1;
                int iRow_Detail_IT = Convert.ToInt16(ws_config.Cells["B10"].Value) - 1;
                int iRow_Detail_FA = Convert.ToInt16(ws_config.Cells["B11"].Value) - 1;
                int iRow_Detail_HR = Convert.ToInt16(ws_config.Cells["B12"].Value) - 1;
                int iRow_Detail_Other = Convert.ToInt16(ws_config.Cells["B13"].Value) - 1;

                //end
                int iRow_End = Convert.ToInt16(ws_config.Cells["B7"].Value) - 1;

                string sNo = ws_config.Cells["B8"].Value.ToString();
                string sGroup1Active = ws_config.Cells["D4"].Value.ToString();
                string sGroup2Active = ws_config.Cells["D5"].Value.ToString();
                string sRowEndActive = ws_config.Cells["D7"].Value.ToString();

                string sGroup1Column = ws_config.Cells["E4"].Value == null ? "" : ws_config.Cells["E4"].Value.ToString();
                string sGroup2Column = ws_config.Cells["E5"].Value == null ? "" : ws_config.Cells["E5"].Value.ToString();

                string sVersionExcel = ws_config.Cells["H5"].Value == null ? "2003" : ws_config.Cells["H5"].Value.ToString();
                string sFileNameExcel = ws_config.Cells["H6"].Value == null ? "" : ws_config.Cells["H6"].Value.ToString();
                string sPassword = ws_config.Cells["H7"].Value == null ? "" : ws_config.Cells["H7"].Value.ToString();
                #endregion

                Worksheet ws = wb.Worksheets[0];

                #region Lay vi tri cac tieu de
                //databind phòng Manager
                ArrayList arr = new ArrayList(); //Mang chua cot detail
                ArrayList arrIndexCol = new ArrayList();
                ArrayList arrIndexFormular = new ArrayList();
                int IndexRow = 0;
                bool bIsSTT = false; //false: khong co Cot STT; //true: co Cot STT

                for (int i = 0; i < iMax_Colum; i++)
                {
                    Cell cTmp = ws.Cells[iRow_Detail, i];
                    string sSearch = cTmp.Value == null ? "" : cTmp.Value.ToString().Trim();

                    if (cTmp.IsFormula == true)
                        arrIndexFormular.Add(cTmp.Column);

                    else
                    {
                        if (sSearch != "" && sSearch.ToUpper() != "NO")
                        {
                            arr.Add(sSearch);
                            arrIndexCol.Add(cTmp.Column);
                            IndexRow = cTmp.Row;
                        }
                    }

                    if (sSearch.ToUpper() == "NO")
                        bIsSTT = true;
                }
                #endregion
                #region lấy vị trí tiêu đề :AF
                //begin
                ArrayList arr_add = new ArrayList(); //Mang chua cot detail
                ArrayList arrIndexCol_add = new ArrayList();
                ArrayList arrIndexFormular_add = new ArrayList();
                int IndexRow_add = 0;
                bool bIsSTT_add = false; //false: khong co Cot STT; //true: co Cot STT
                //end

                //begin
                for (int i = 0; i < iMax_Colum; i++)
                {
                    Cell cTmp = ws.Cells[iRow_Detail_AF, i];
                    string sSearch = cTmp.Value == null ? "" : cTmp.Value.ToString().Trim();

                    if (cTmp.IsFormula == true)
                        arrIndexFormular_add.Add(cTmp.Column);

                    else
                    {
                        if (sSearch != "" && sSearch.ToUpper() != "NO")
                        {
                            arr_add.Add(sSearch);
                            arrIndexCol_add.Add(cTmp.Column);
                            IndexRow_add = cTmp.Row;
                        }
                    }

                    if (sSearch.ToUpper() == "NO")
                        bIsSTT_add = true;
                }
                //end
                #endregion
                #region Lấy vị trí tiêu đề :IT
                //begin
                ArrayList arr_IT = new ArrayList(); //Mang chua cot detail
                ArrayList arrIndexCol_IT = new ArrayList();
                ArrayList arrIndexFormular_IT = new ArrayList();
                int IndexRow_IT = 0;
                bool bIsSTT_IT = false; //false: khong co Cot STT; //true: co Cot STT
                //end

                //begin
                for (int i = 0; i < iMax_Colum; i++)
                {
                    Cell cTmp = ws.Cells[iRow_Detail_IT, i];
                    string sSearch = cTmp.Value == null ? "" : cTmp.Value.ToString().Trim();

                    if (cTmp.IsFormula == true)
                        arrIndexFormular_IT.Add(cTmp.Column);

                    else
                    {
                        if (sSearch != "" && sSearch.ToUpper() != "NO")
                        {
                            arr_IT.Add(sSearch);
                            arrIndexCol_IT.Add(cTmp.Column);
                            IndexRow_IT = cTmp.Row;
                        }
                    }

                    if (sSearch.ToUpper() == "NO")
                        bIsSTT_IT = true;
                }
                //end
                #endregion
                #region lấy vị trí tiêu đề :FA
                //databind phòng Manager
                ArrayList arr_FA = new ArrayList(); //Mang chua cot detail
                ArrayList arrIndexCol_FA = new ArrayList();
                ArrayList arrIndexFormular_FA = new ArrayList();
                int IndexRow_FA = 0;
                bool bIsSTT_FA = false; //false: khong co Cot STT; //true: co Cot STT
                for (int i = 0; i < iMax_Colum; i++)
                {
                    Cell cTmp = ws.Cells[iRow_Detail_FA, i];
                    string sSearch = cTmp.Value == null ? "" : cTmp.Value.ToString().Trim();

                    if (cTmp.IsFormula == true)
                        arrIndexFormular_FA.Add(cTmp.Column);

                    else
                    {
                        if (sSearch != "" && sSearch.ToUpper() != "NO")
                        {
                            arr_FA.Add(sSearch);
                            arrIndexCol_FA.Add(cTmp.Column);
                            IndexRow_FA = cTmp.Row;
                        }
                    }
                    if (sSearch.ToUpper() == "NO")
                        bIsSTT_FA = true;
                }
                #endregion
                #region Lấy vị trí tiêu đề :HR
                //begin
                ArrayList arr_HR = new ArrayList(); //Mang chua cot detail
                ArrayList arrIndexCol_HR = new ArrayList();
                ArrayList arrIndexFormular_HR = new ArrayList();
                int IndexRow_HR = 0;
                bool bIsSTT_HR = false; //false: khong co Cot STT; //true: co Cot STT
                //end

                //begin
                for (int i = 0; i < iMax_Colum; i++)
                {
                    Cell cTmp = ws.Cells[iRow_Detail_HR, i];
                    string sSearch = cTmp.Value == null ? "" : cTmp.Value.ToString().Trim();

                    if (cTmp.IsFormula == true)
                        arrIndexFormular_HR.Add(cTmp.Column);

                    else
                    {
                        if (sSearch != "" && sSearch.ToUpper() != "NO")
                        {
                            arr_HR.Add(sSearch);
                            arrIndexCol_HR.Add(cTmp.Column);
                            IndexRow_HR = cTmp.Row;
                        }
                    }

                    if (sSearch.ToUpper() == "NO")
                        bIsSTT_HR = true;
                }
                //end
                #endregion
                #region lấy vị trí tiêu đề :Other
                //databind phòng Manager
                ArrayList arr_Other = new ArrayList(); //Mang chua cot detail
                ArrayList arrIndexCol_Other = new ArrayList();
                ArrayList arrIndexFormular_Other = new ArrayList();
                int IndexRow_Other = 0;
                bool bIsSTT_Other = false; //false: khong co Cot STT; //true: co Cot STT
                for (int i = 0; i < iMax_Colum; i++)
                {
                    Cell cTmp = ws.Cells[iRow_Detail_Other, i];
                    string sSearch = cTmp.Value == null ? "" : cTmp.Value.ToString().Trim();

                    if (cTmp.IsFormula == true)
                        arrIndexFormular_Other.Add(cTmp.Column);

                    else
                    {
                        if (sSearch != "" && sSearch.ToUpper() != "NO")
                        {
                            arr_Other.Add(sSearch);
                            arrIndexCol_Other.Add(cTmp.Column);
                            IndexRow_Other = cTmp.Row;
                        }
                    }
                    if (sSearch.ToUpper() == "NO")
                        bIsSTT_Other = true;
                }
                #endregion
                if (dtData != null)
                {
                    if (dtData.Rows.Count > 0)
                    {
                        #region insert cac detail
                        for (int i = 0; i < arr.Count; i++)
                        {
                            if (i == 0)
                            {
                                try
                                {
                                    ws.Cells.ImportDataColumn(dtData, false, IndexRow, Convert.ToInt16(arrIndexCol[i]), arr[i].ToString(), true);
                                }
                                catch
                                {
                                    ws.Cells[IndexRow, Convert.ToInt16(arrIndexCol[i])].PutValue(null);
                                }
                            }
                            else
                            {
                                try
                                {
                                    ws.Cells.ImportDataColumn(dtData, false, IndexRow, Convert.ToInt16(arrIndexCol[i]), arr[i].ToString(), false);
                                }
                                catch
                                {
                                    ws.Cells[IndexRow, Convert.ToInt16(arrIndexCol[i])].PutValue(null);
                                }
                            }
                        }

                        //--Sao chep cong thuc

                        for (int i = 0; i < arrIndexFormular.Count; i++)
                        {
                            Cell sTmp = ws.Cells[iRow_Detail, Convert.ToInt16(arrIndexFormular[i])];

                            for (int j = iRow_Detail + 1; j < iRow_Detail + dtData.Rows.Count; j++)
                            {
                                ws.Cells[j, Convert.ToInt16(arrIndexFormular[i])].Copy(sTmp);
                            }
                        }
                        //--End
                        ws.Cells.DeleteRow(IndexRow + dtData.Rows.Count);
                        #endregion
                    }
                    else
                        ws.Cells.DeleteRow(iRow_Detail);
                }
                int rowAF = 0;
                if (dtData_AF.Rows.Count > 0)
                {
                    rowAF = this.ExportDMProperty(iRow_Detail_AF, dtData.Rows.Count, dtData_AF, iMax_Colum, ws, arr_add, arrIndexCol_add, arrIndexFormular_add, IndexRow_add);
                }
                else
                {
                    if (dtData.Rows.Count <= 0)
                    {
                        rowAF = this.ExportDMProperty(iRow_Detail_AF, dtData.Rows.Count, dtData_AF, iMax_Colum, ws, arr_add, arrIndexCol_add, arrIndexFormular_add, IndexRow_add);
                    }
                    else
                        rowAF = this.ExportDMProperty(iRow_Detail_AF + 1, dtData.Rows.Count, dtData_AF, iMax_Colum, ws, arr_add, arrIndexCol_add, arrIndexFormular_add, IndexRow_add);
                }
                int rowIT = 0;
                if (dtData_IT.Rows.Count > 0)
                {
                    rowIT = this.ExportDMProperty(iRow_Detail_IT, rowAF + dtData.Rows.Count - 1, dtData_IT, iMax_Colum, ws, arr_IT, arrIndexCol_IT, arrIndexFormular_IT, IndexRow_IT);
                }
                else
                {
                    if (rowAF <= 0 && dtData.Rows.Count <= 0)
                    {
                        rowIT = this.ExportDMProperty(iRow_Detail_IT - 1, rowAF + dtData.Rows.Count - 1, dtData_IT, iMax_Colum, ws, arr_IT, arrIndexCol_IT, arrIndexFormular_IT, IndexRow_IT);
                    }
                    else if ((rowAF <= 0 && dtData.Rows.Count > 0) || rowAF > 0 && dtData.Rows.Count <= 0)
                    {
                        rowIT = this.ExportDMProperty(iRow_Detail_IT, rowAF + dtData.Rows.Count - 1, dtData_IT, iMax_Colum, ws, arr_IT, arrIndexCol_IT, arrIndexFormular_IT, IndexRow_IT);
                    }
                    else
                        rowIT = this.ExportDMProperty(iRow_Detail_IT + 1, rowAF + dtData.Rows.Count - 1, dtData_IT, iMax_Colum, ws, arr_IT, arrIndexCol_IT, arrIndexFormular_IT, IndexRow_IT);
                }
                int rowFA = 0;
                if (dtData_FA.Rows.Count > 0)
                {
                    rowFA = this.ExportDMProperty(iRow_Detail_FA, rowAF + rowIT + dtData.Rows.Count - 2, dtData_FA, iMax_Colum, ws, arr_FA, arrIndexCol_FA, arrIndexFormular_FA, IndexRow_FA);
                }
                else
                {
                    if (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT <= 0)
                    {
                        rowFA = this.ExportDMProperty(iRow_Detail_FA - 2, rowAF + rowIT + dtData.Rows.Count - 2, dtData_FA, iMax_Colum, ws, arr_FA, arrIndexCol_FA, arrIndexFormular_FA, IndexRow_FA);
                    }
                    else if ((rowAF <= 0 && dtData.Rows.Count > 0 && rowIT <= 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT <= 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT > 0))
                    {
                        rowFA = this.ExportDMProperty(iRow_Detail_FA - 1, rowAF + rowIT + dtData.Rows.Count - 2, dtData_FA, iMax_Colum, ws, arr_FA, arrIndexCol_FA, arrIndexFormular_FA, IndexRow_FA);
                    }
                    else if ((rowAF > 0 && dtData.Rows.Count > 0 && rowIT <= 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT > 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT > 0))
                    {
                        rowFA = this.ExportDMProperty(iRow_Detail_FA, rowAF + rowIT + dtData.Rows.Count - 2, dtData_FA, iMax_Colum, ws, arr_FA, arrIndexCol_FA, arrIndexFormular_FA, IndexRow_FA);
                    }
                    else
                        rowFA = this.ExportDMProperty(iRow_Detail_FA + 1, rowAF + rowIT + dtData.Rows.Count - 2, dtData_FA, iMax_Colum, ws, arr_FA, arrIndexCol_FA, arrIndexFormular_FA, IndexRow_FA);


                }
                int rowHR = 0;
                if (dtData_HR.Rows.Count > 0)
                {
                    rowHR = this.ExportDMProperty(iRow_Detail_HR, rowIT + rowFA + rowAF + dtData.Rows.Count - 3, dtData_HR, iMax_Colum, ws, arr_HR, arrIndexCol_HR, arrIndexFormular_HR, IndexRow_HR);
                }
                else
                {

                    if (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA <= 0)
                    {
                        rowHR = this.ExportDMProperty(iRow_Detail_HR - 3, rowIT + rowFA + rowAF + dtData.Rows.Count - 3, dtData_HR, iMax_Colum, ws, arr_HR, arrIndexCol_HR, arrIndexFormular_HR, IndexRow_HR);
                    }
                    else if ((rowAF > 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA <= 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA <= 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA <= 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA > 0))
                    {
                        rowHR = this.ExportDMProperty(iRow_Detail_HR - 2, rowIT + rowFA + rowAF + dtData.Rows.Count - 3, dtData_HR, iMax_Colum, ws, arr_HR, arrIndexCol_HR, arrIndexFormular_HR, IndexRow_HR);
                    }
                    else if ((rowAF > 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA <= 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA <= 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA > 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA <= 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA > 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA > 0))
                    {
                        rowHR = this.ExportDMProperty(iRow_Detail_HR - 1, rowIT + rowFA + rowAF + dtData.Rows.Count - 3, dtData_HR, iMax_Colum, ws, arr_HR, arrIndexCol_HR, arrIndexFormular_HR, IndexRow_HR);
                    }
                    else if ((rowAF > 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA <= 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA > 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA > 0) || (rowAF > 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA > 0))
                        rowHR = this.ExportDMProperty(iRow_Detail_HR, rowIT + rowFA + rowAF + dtData.Rows.Count - 3, dtData_HR, iMax_Colum, ws, arr_HR, arrIndexCol_HR, arrIndexFormular_HR, IndexRow_HR);
                    else
                        rowHR = this.ExportDMProperty(iRow_Detail_HR + 1, rowIT + rowFA + rowAF + dtData.Rows.Count - 3, dtData_HR, iMax_Colum, ws, arr_HR, arrIndexCol_HR, arrIndexFormular_HR, IndexRow_HR);

                }
                int rowOther = 0;
                if (dtData_Other.Rows.Count > 0)
                {
                    rowOther = this.ExportDMProperty(iRow_Detail_Other, rowHR + rowFA + rowAF + rowIT + dtData.Rows.Count - 4, dtData_Other, iMax_Colum, ws, arr_Other, arrIndexCol_Other, arrIndexFormular_Other, IndexRow_Other);
                }
                else
                {
                    if (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA <= 0 && rowHR <= 0)
                    {
                        rowOther = this.ExportDMProperty(iRow_Detail_Other - 4, rowHR + rowFA + rowAF + rowIT + dtData.Rows.Count - 4, dtData_Other, iMax_Colum, ws, arr_Other, arrIndexCol_Other, arrIndexFormular_Other, IndexRow_Other);
                    }
                    else if ((rowAF > 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA <= 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA <= 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA <= 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA > 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA <= 0 && rowHR > 0))
                    {
                        rowOther = this.ExportDMProperty(iRow_Detail_Other - 3, rowHR + rowFA + rowAF + rowIT + dtData.Rows.Count - 4, dtData_Other, iMax_Colum, ws, arr_Other, arrIndexCol_Other, arrIndexFormular_Other, IndexRow_Other);
                    }
                    else if ((rowAF > 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA <= 0 && rowHR <= 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA <= 0 && rowHR <= 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA > 0 && rowHR <= 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA <= 0 && rowHR > 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA <= 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA > 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA <= 0 && rowHR > 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA > 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count <= 0 && rowIT <= 0 && rowFA > 0 && rowHR > 0))
                    {
                        rowOther = this.ExportDMProperty(iRow_Detail_Other - 2, rowHR + rowFA + rowAF + rowIT + dtData.Rows.Count - 4, dtData_Other, iMax_Colum, ws, arr_Other, arrIndexCol_Other, arrIndexFormular_Other, IndexRow_Other);
                    }
                    else if ((rowAF > 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA <= 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA > 0 && rowHR <= 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA > 0 && rowHR <= 0) || (rowAF > 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA > 0 && rowHR <= 0))
                        rowOther = this.ExportDMProperty(iRow_Detail_Other - 1, rowHR + rowFA + rowAF + rowIT + dtData.Rows.Count - 4, dtData_Other, iMax_Colum, ws, arr_Other, arrIndexCol_Other, arrIndexFormular_Other, IndexRow_Other);
                    else if ((rowAF > 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA > 0 && rowHR <= 0) || (rowAF <= 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA > 0 && rowHR > 0) || (rowAF > 0 && dtData.Rows.Count <= 0 && rowIT > 0 && rowFA > 0 && rowHR > 0) || (rowAF > 0 && dtData.Rows.Count > 0 && rowIT <= 0 && rowFA > 0 && rowHR > 0) || (rowAF > 0 && dtData.Rows.Count > 0 && rowIT > 0 && rowFA <= 0 && rowHR > 0))
                        rowOther = this.ExportDMProperty(iRow_Detail_Other, rowHR + rowFA + rowAF + rowIT + dtData.Rows.Count - 4, dtData_Other, iMax_Colum, ws, arr_Other, arrIndexCol_Other, arrIndexFormular_Other, IndexRow_Other);
                    else
                        rowOther = this.ExportDMProperty(iRow_Detail_Other + 1, rowHR + rowFA + rowAF + rowIT + dtData.Rows.Count - 4, dtData_Other, iMax_Colum, ws, arr_Other, arrIndexCol_Other, arrIndexFormular_Other, IndexRow_Other);

                }
                #region replace parametter
                ArrayList arrReplace = new ArrayList();
                if (dtReplace != null)
                {
                    for (int i = 0; i < dtReplace.Columns.Count; i++)
                    {
                        string sColumnName = dtReplace.Columns[i].ToString();
                        object sColumnValue = dtReplace.Rows[0][sColumnName];

                        Cell c = ws.Cells.FindString("$" + sColumnName + "$", null);
                        if (c == null)
                            ws.Replace("$" + sColumnName + "$", sColumnValue.ToString());
                        else
                            c.PutValue(sColumnValue);
                    }
                }
                #endregion

                #region Password
                if (sPassword.Trim() != "")
                    ws.Protect(ProtectionType.All, sPassword, null);
                #endregion

                ws.Cells.DeleteRow(iRow_Group1);
                ws.Cells.DeleteRow(iRow_Group1);

                wb.Worksheets.RemoveAt(1);
                // wb.Worksheets.RemoveAt(1);


                MemoryStream Stream = new MemoryStream();
                FileFormatType Format = new Aspose.Cells.FileFormatType();

                if (sVersionExcel == "2007")
                {
                    Format = Aspose.Cells.FileFormatType.Excel2007Xlsx;
                    sFileNameExcel += ".xlsx";
                }

                else
                {
                    Format = Aspose.Cells.FileFormatType.Excel2003;
                    sFileNameExcel += ".xls";
                }
                wb.Save(Stream, Format);
                HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + sFileNameExcel);
                HttpContext.Current.Response.BinaryWrite(Stream.ToArray());
                HttpContext.Current.Response.End();

                return "";
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
            return "";
        }
        #region xuất danh mục đã tồn tại
        public int ExportDMProperty(int rowDetail, int rowBefore, DataTable datAF, int maxColumn, Worksheet ws, ArrayList arr_add
                , ArrayList arrIndexCol_add
                , ArrayList arrIndexFormular_add
                , int IndexRow_add)
        {
            try
            {

                //begin
                if (datAF != null)
                {

                    if (datAF.Rows.Count > 0)
                    {
                        #region insert cac detail
                        for (int i = 0; i < arr_add.Count; i++)
                        {
                            if (i == 0)
                            {
                                try
                                {
                                    ws.Cells.ImportDataColumn(datAF, false, IndexRow_add + rowBefore - 1, Convert.ToInt16(arrIndexCol_add[i]), arr_add[i].ToString(), true);
                                }
                                catch
                                {
                                    ws.Cells[IndexRow_add, Convert.ToInt16(arrIndexCol_add[i])].PutValue(null);
                                }
                            }
                            else
                            {
                                try
                                {
                                    ws.Cells.ImportDataColumn(datAF, false, IndexRow_add + rowBefore - 1, Convert.ToInt16(arrIndexCol_add[i]), arr_add[i].ToString(), false);
                                }
                                catch
                                {
                                    ws.Cells[IndexRow_add, Convert.ToInt16(arrIndexCol_add[i])].PutValue(null);
                                }
                            }
                        }

                        //--Sao chep cong thuc

                        for (int i = 0; i < arrIndexFormular_add.Count; i++)
                        {
                            Cell sTmp = ws.Cells[rowDetail, Convert.ToInt16(arrIndexFormular_add[i])];

                            for (int j = rowDetail + 1; j < rowDetail; j++)
                            {
                                ws.Cells[j, Convert.ToInt16(arrIndexFormular_add[i])].Copy(sTmp);
                            }
                        }
                        //--End

                        ws.Cells.DeleteRow(IndexRow_add + rowBefore + datAF.Rows.Count - 1);
                        #endregion

                    }
                    else
                        ws.Cells.DeleteRow(rowDetail);

                }
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
            return datAF.Rows.Count;
        }
        #endregion
        #region xuất danh mục chưa tồn tại
        public int ExportNotDMProperty(int rowDetail, int rowBefore, DataTable datAF, int maxColumn, Worksheet ws, ArrayList arr_add
                , ArrayList arrIndexCol_add
                , ArrayList arrIndexFormular_add
                , int IndexRow_add)
        {
            try
            {

                //begin
                if (datAF != null)
                {

                    if (datAF.Rows.Count > 0)
                    {
                        #region insert cac detail
                        for (int i = 0; i < arr_add.Count; i++)
                        {
                            if (i == 0)
                            {
                                try
                                {
                                    ws.Cells.ImportDataColumn(datAF, false, IndexRow_add + rowBefore - 1, Convert.ToInt16(arrIndexCol_add[i]), arr_add[i].ToString(), true);
                                }
                                catch
                                {
                                    ws.Cells[IndexRow_add, Convert.ToInt16(arrIndexCol_add[i])].PutValue(null);
                                }
                            }
                            else
                            {
                                try
                                {
                                    ws.Cells.ImportDataColumn(datAF, false, IndexRow_add + rowBefore - 1, Convert.ToInt16(arrIndexCol_add[i]), arr_add[i].ToString(), false);
                                }
                                catch
                                {
                                    ws.Cells[IndexRow_add, Convert.ToInt16(arrIndexCol_add[i])].PutValue(null);
                                }
                            }
                        }

                        //--Sao chep cong thuc

                        for (int i = 0; i < arrIndexFormular_add.Count; i++)
                        {
                            Cell sTmp = ws.Cells[rowDetail, Convert.ToInt16(arrIndexFormular_add[i])];

                            for (int j = rowDetail + 1; j < rowDetail; j++)
                            {
                                ws.Cells[j, Convert.ToInt16(arrIndexFormular_add[i])].Copy(sTmp);
                            }
                        }
                        //--End

                        ws.Cells.DeleteRow(IndexRow_add + rowBefore + datAF.Rows.Count - 1);
                        #endregion

                    }
                    else
                        ws.Cells.DeleteRow(rowDetail + 1);

                }
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
            return datAF.Rows.Count;
        }
        #endregion
        #endregion

        public void Submit_K2()
        {
            try
            {
                //Insert history comment trên eform (dùng cho approver list)
                TER_ExitFormCollection cl_exit = new TER_ExitFormCollection();
                string processid = cl_exit.GetProcessid(EmpHeader.EmployeeId);
                K2Collection col_k2=new K2Collection();
                vHCS.SYS.Business.SYS_MailTemplateCollection col_mail=new SYS.Business.SYS_MailTemplateCollection();
                string sharedUser = Request.QueryString["SharedUser"] != null ? Request.QueryString["SharedUser"].ToString() : string.Empty;
                int processInstance = K2CoreLib.K2Utils.GetWorklistItem(hdfsn.Value, sharedUser).ProcessInstance.ID;
                string countapprove = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "CountApprove", sharedUser);
                string allapprove = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "AllApprove", sharedUser);
                string hrp = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "HRBP", sharedUser);
                string hr_excutor = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "HRExcutor", sharedUser);
                string requester = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "Requester", sharedUser);
                string processCode = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "ProcessCode", sharedUser);
                string Empid = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "EmpID", sharedUser);
                string IsReturn = K2CoreLib.K2Utils.GetDataField(hdfsn.Value, "IsReturn", sharedUser);
                Int32 int_countapprove = Convert.ToInt32(string.IsNullOrEmpty(countapprove) ? "0" : countapprove);
                Int32 int_allapprove = Convert.ToInt32(string.IsNullOrEmpty(allapprove) ? "0" : allapprove);
                List<string> NextApprove = new List<string>();
                string Approver = "";
                string Actions = "Approve";

                #region Kiểm tra cấp phê duyệt hiện tại
                //Kiểm tra số lượng người approve đã đủ để chuyển sang hrp duyệt hay chưa
                //Nếu chưa thì +1 cho countapprove
                //Nếu đã có thì gán các cấp phê duyệt thì gán hrp
                if (int_countapprove < int_allapprove)
                {
                    NextApprove.Add("CountApprove");
                    NextApprove.Add((int_countapprove + 1).ToString());
                }

                if ((int_countapprove + 1) >= int_allapprove)//Nếu đã duyệt đủ số lượng approver của các phòng ban
                {
                    if (IsReturn == "1") //Nếu như thông tin trả về đã được phê duyệt thì gán IsReturn=0
                    {
                        NextApprove.Add("IsReturn");
                        NextApprove.Add("0");

                        DataTable dat = new DataTable();
                        dat = col_k2.GetComboCheckList(EmpHeader.EmployeeId);
                        if (dat.Rows.Count > 0)
                        {
                            foreach (DataRow row in dat.Rows)
                            {
                                NextApprove.Add(row["Id"].ToString());
                                NextApprove.Add("0");
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(hrp)) //Nếu HRBP chưa phê duyệt thì gán người HRBP phê duyệt
                    {
                        NextApprove.Add("HRBP");
                        Approver = col_k2.GetUserOfHRP_Province(EmpHeader.EmployeeId);
                        NextApprove.Add(Approver);
                        NextApprove.Add("MailHRBP");
                        NextApprove.Add(col_mail.ReturnEmail(Approver));
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(hr_excutor)) //Gán cấp phê duyệt C&B
                        {
                            NextApprove.Add("HRExcutor");
                            Approver = cboExcutor.SelectedValue;
                            NextApprove.Add(Approver);
                            NextApprove.Add("MailExcutor");
                            NextApprove.Add(col_mail.ReturnEmail(Approver));

                            #region Gán thông tin gửi mail khi HR execute
                            //SYS_MailTemplateDTO _mailHrExecute = new SYS_MailTemplateDTO();
                            //_mailHrExecute = col_mail.GetMailContentWithSignature("ExitCheckList_Excute", "K2-Signature");

                            //string MailContent_Excute = _mailHrExecute.ContentVN; //col_mail.ReturnMailContent("ExitCheckList_Excute");
                            //MailContent_Excute = MailContent_Excute.Replace("$Creator$", requester);
                            //MailContent_Excute = MailContent_Excute.Replace("$url$", ConfigurationManager.AppSettings.Get("ExitCheckListHis") + Empid + "&ProcessID=" + processid);

                            //string MailSubject_Excute = _mailHrExecute.TitleVN;// col_mail.ReturnSubjectMail("ExitCheckList_Excute");
                            //MailSubject_Excute = MailSubject_Excute.Replace("$Creator$", requester);
                            //MailSubject_Excute = MailSubject_Excute.Replace("$Status$", "Approved");

                            //NextApprove.Add("MailSubject_Excute");
                            //NextApprove.Add(MailSubject_Excute);
                            //NextApprove.Add("MailContent_Excute");
                            //NextApprove.Add(MailContent_Excute);
                            #endregion
                        }
                        else
                        {
                            if (cboActions.SelectedValue == "Return") //Nếu cấp phê duyệt C&B trả về các role trước
                            {
                                int i = 0;
                                //Gán số lượng các cấp phê duyệt và thông tin các cấp cần phê duyệt lại
                                foreach (ListItem item in chkReturn.Items)
                                {
                                    if (item.Selected == true)
                                    {
                                        NextApprove.Add(item.Value);
                                        NextApprove.Add("1");
                                        i++;
                                    }
                                }

                                //Gán lại thông tin số lượng người phê duyệt
                                NextApprove.Add("CountApprove");
                                NextApprove.Add("0");
                                NextApprove.Add("AllApprove");
                                NextApprove.Add(i.ToString());
                                NextApprove.Add("IsReturn");
                                NextApprove.Add("1");
                                //

                                Actions = "Return";
                            }
                        }
                    }

                    #region Gán thông tin gửi mail cho requester biết đang chờ ai phê duyệt
                    SYS_MailTemplateDTO _mailRequester = new SYS_MailTemplateDTO();
                    _mailRequester = col_mail.GetMailContentWithSignature("K2-Notify", "K2-Signature");

                    string MailContent_Waiting = _mailRequester.ContentVN; //col_mail.ReturnMailContent("ExitCheckList_Waiting");
                    MailContent_Waiting = MailContent_Waiting.Replace("$TicketName$", _TicketName__);
                    MailContent_Waiting = MailContent_Waiting.Replace("$ContentTicket$", "");
                    MailContent_Waiting = MailContent_Waiting.Replace("$url$", ConfigurationManager.AppSettings.Get("ExitCheckListHis") + Empid + "&ProcessID=" + processid);
                    MailContent_Waiting = MailContent_Waiting.Replace("$Approver$", SessionManager.UserDomain);
                    MailContent_Waiting = MailContent_Waiting.Replace("$Status$", cboActions.SelectedValue == "Return" ? "Return" : "Approve");

                    string MailSubject_Waiting = _mailRequester.TitleVN; // col_mail.ReturnSubjectMail("ExitCheckList_Waiting");
                    MailSubject_Waiting = MailSubject_Waiting.Replace("$Creator$", requester);
                    MailSubject_Waiting = MailSubject_Waiting.Replace("$Approver$", SessionManager.UserDomain);
                    MailSubject_Waiting = MailSubject_Waiting.Replace("$TicketName$", _TicketName__);
                    MailSubject_Waiting = MailSubject_Waiting.Replace("$Code$", processCode);
                    MailSubject_Waiting = MailSubject_Waiting.Replace("$Status$", cboActions.SelectedValue == "Return" ? "Return" : "Approve");

                    NextApprove.Add("MailSubject_Waiting");
                    NextApprove.Add(MailSubject_Waiting);
                    NextApprove.Add("MailContent_Waiting");
                    NextApprove.Add(MailContent_Waiting);

                    #endregion
                }

                #region Lưu thông tin history
                HR_WorkingRecordCollection cl_wr = new HR_WorkingRecordCollection();
                string Hisstatus = "Approved";

                if (cboActions.SelectedValue == "Return")
                    Hisstatus = "Return";
                else
                    if (!string.IsNullOrEmpty(hr_excutor) && IsReturn=="0")
                        Hisstatus = "Finished";

                //Lưu history
                cl_wr.InsertHistory(Convert.ToInt64(cl_exit.GetProcessid(EmpHeader.EmployeeId)), DateTime.Now, SessionManager.UserDomain, "Approver Step", Hisstatus, "", 5,Convert.ToInt64(hdfRoleID.Value));
                #endregion

                #region Gán thông tin gửi mail khi approve

                if (Hisstatus.Equals("Finished"))
                {
                    SYS_MailTemplateDTO _mailApprove = new SYS_MailTemplateDTO();
                    _mailApprove = col_mail.GetMailContentWithSignature("K2-Finished", "K2-Signature");
                    string MailContent_Approve = _mailApprove.ContentVN; 
                    string MailSubject_Approve = _mailApprove.TitleVN;

                    //Gán thông tin content mail approve
                    MailContent_Approve = MailContent_Approve.Replace("$TicketName$", _TicketName__);
                    MailContent_Approve = MailContent_Approve.Replace("$ContentTicket$", "");
                    MailContent_Approve = MailContent_Approve.Replace("$url$", ConfigurationManager.AppSettings.Get("ExitCheckListHis") + Empid + "&ProcessID=" + cl_exit.GetProcessid(EmpHeader.EmployeeId));

                    //Gán thông tin subject mail approve
                    MailSubject_Approve = MailSubject_Approve.Replace("$Code$", processCode);
                    MailSubject_Approve = MailSubject_Approve.Replace("$TicketName$", _TicketName__);

                    string EmailApprover = col_mail.ReturnEmail(SessionManager.UserDomain);

                    NextApprove.Add("MailApprover");
                    NextApprove.Add(EmailApprover);
                    NextApprove.Add("MailSubject_Approve");
                    NextApprove.Add(MailSubject_Approve);
                    NextApprove.Add("MailContent_Approve");
                    NextApprove.Add(MailContent_Approve);
                }
                //SYS_MailTemplateDTO _mailApprove = new SYS_MailTemplateDTO();
                //_mailApprove = col_mail.GetMailContentWithSignature("ExitCheckList_Approve", "K2-Signature");
                //string MailContent_Approve = _mailApprove.ContentVN; //col_mail.ReturnMailContent("ExitCheckList_Approve");
                //string MailSubject_Approve = _mailApprove.TitleVN;

                ////Gán thông tin content mail approve
                //MailContent_Approve = MailContent_Approve.Replace("$Creator$",requester);
                //MailContent_Approve = MailContent_Approve.Replace("$Approver$", SessionManager.UserDomain);
                //MailContent_Approve = MailContent_Approve.Replace("$url$", ConfigurationManager.AppSettings.Get("ExitCheckListHis") + Empid + "&ProcessID=" + cl_exit.GetProcessid(EmpHeader.EmployeeId));

                ////Gán thông tin subject mail approve
                //MailSubject_Approve = MailSubject_Approve.Replace("$Dept$",SessionManager.UserDomain);
                //MailSubject_Approve = MailSubject_Approve.Replace("$Creator$", requester);

                //string EmailApprover = col_mail.ReturnEmail(SessionManager.UserDomain);

                //NextApprove.Add("MailApprover");
                //NextApprove.Add(EmailApprover);
                //NextApprove.Add("MailSubject_Approve");
                //NextApprove.Add(MailSubject_Approve);
                //NextApprove.Add("MailContent_Approve");
                //NextApprove.Add(MailContent_Approve);
                #endregion

                #endregion

                #region Xử lý phê duyệt K2
                K2CoreLib.K2Utils.ActionExecute(hdfsn.Value, Actions, sharedUser, NextApprove.ToArray());
                btnTopSave.Enabled = false;
                btnBottomSave.Enabled = false;

                //Insert History Comment
                K2CoreLib.K2Utils.InsertHistoryComment(processid, SessionManager.UserDomain);
                #endregion
            }
            catch (Exception ex)
            {
                AlertMessage mess = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(mess);
            }
        }


    }
}